import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import pub.tbc.toolkit.Loops;
import redis.clients.jedis.Jedis;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

/**
 * @author tbc on 2016/11/30 22:47.
 */
public class MessageToRedisMQ {
    public static void main(String[] args) {
        int msgCount = 500;
        long startTime = System.currentTimeMillis();
        Jedis jedis = new Jedis("192.168.2.20", 6379);
        String key = "task.queue.test.key";
        Loops.times(msgCount, it -> {
            jedis.rpush(key, getTask1());
            jedis.rpush(key, getTask1());
            jedis.rpush(key, getTask2());
            jedis.rpush(key, getTask2());
        });
        System.out.println(msgCount * 4 + "条消息发送完成，共耗时：" + (System.currentTimeMillis() - startTime));
    }

//    public static void main(String[] args){
//        System.out.println(getTask1());
//        System.out.println(getTask2());
//    }

    public static String getTask1() {
        String requestId = UUID.randomUUID().toString();
        return TaskBean.builder().requestId(requestId).url("http://it:8080/demo1").httpMethod("get").param(null).paramType("path_param").timestamp(Date.from(Instant.now())).build().toString();
    }

    public static String getTask2() {
        String requestId = UUID.randomUUID().toString();
//        return TaskBean.builder().requestId(requestId).url("http://211.157.179.221:22100/yijiajiao-wares/basic/grades").httpMethod("get").param(null).paramType("path_param").timestamp(Date.from(Instant.now())).build().toString();
        return TaskBean.builder().requestId(requestId).url("http://it:8080/demo2").httpMethod("get").param(null).paramType("path_param").timestamp(Date.from(Instant.now())).build().toString();

    }


    @Data
    @Builder
    private static class TaskBean {
        private String requestId;
        private String url;
        private String httpMethod;
        private String param;
        private String paramType;
        private Date timestamp;

        @Override
        public String toString() {
            return JSON.toJSONString(this, SerializerFeature.WriteMapNullValue);
        }
    }
}
